package chartCraft.tableDesk;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;

import chartCraft.ChartCraftController;
import chartCraft.model.TopModel;

public class RemoveTimeButton extends JButton implements ActionListener, Observer{
	private static final long serialVersionUID = 1L;
	private ChartCraftController mChartCraftController;
	private TopModel mTopModel;

	public RemoveTimeButton(ChartCraftController chartCraftController, TopModel topModel) {
		super("-");
		mChartCraftController = chartCraftController;
		setModel(topModel);
		
		updateMyView();
		addActionListener(this);
	}
	
	private void updateMyView() {
		if (mTopModel.getNoOfTime() <= 1) {
			setEnabled(false);
		} else {
			setEnabled(true);
		}
	}

	public void setModel(TopModel model) {
		mTopModel = model;
		mTopModel.addObserver(this);
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		updateMyView();
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		mChartCraftController.removeTime();
	}
}
